1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import sun.net.util.*;
25
26
27
28
29 public class IPAddressUtilTest {
30 final static Boolean good = Boolean.TRUE;
31 final static Boolean bad = Boolean.FALSE;
32
33 static Object [][] assertions = {
34 {"224.0.1.0", good},
35 {"238.255.255.255", good},
36 {"239.255.255.255", good},
37 {"238.255.255.2550", bad},
38 {"256.255.255.255", bad},
39 {"238.255.2550.255", bad},
40 {"238.2550.255.255", bad},
41 {"2380.255.255.255", bad},
42 {"10::10", good},
43 {"10::10.1", bad},
44 {"10::10.1.2", bad},
45 {"10::10.1.2.3", good},
46 {"10::10.1.2.3.4", bad},
47 {"10::10.", bad},
48 {"10::.10.", bad},
49 {"10::.10", bad}
50 };
51
52 public static void main(String[] args) {
53 for (int i=0; i<assertions.length; i++) {
54 String addr = (String) assertions[i][0];
55 boolean expected = ((Boolean) assertions[i][1]).booleanValue();
56
57 boolean result = true;
58
59 if (!IPAddressUtil.isIPv4LiteralAddress(addr) &&
60 !IPAddressUtil.isIPv6LiteralAddress(addr)) {
61 result = false;
62 }
63
64 if (result != expected) {
65 throw new RuntimeException ("wrong result for " + addr);
66 }
67 }
68 }
69 }